import isLogin from "@/utils/isLogin";
import type { NavigationGuardNext, RouteLocationNormalized } from "vue-router";

export default function authGuard(
    to: RouteLocationNormalized,
    from: RouteLocationNormalized,
    next: NavigationGuardNext
) {
    //用户在没有登录的情况下可以访问的路由路径(白名单)
    const whiteList = ["/", "/login", "/login/callback"]
    //判断用户即将访问的页面是否不在白名单，判断用户是否登录
    if (!whiteList.includes(to.path) && !isLogin()) {
        //跳转到登录页面
        return next({ path: "login", query: { return: to.fullPath } })
    }
    //
    next()
}